import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import '../utils/tools/save_utils.dart';
import 'global_config.dart';

/// 全局配置
class AppConfig {
  /// 初始化
  static Future init() async {
    WidgetsFlutterBinding.ensureInitialized();
    //初始化设备方向
    await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
    //初始化缓存工具
    await SaveUtils.getInstance();
    //初始化UI
    setSystemUi();
  }

  static void setSystemUi() {
    if (GetPlatform.isAndroid) {
      SystemUiOverlayStyle systemUiOverlayStyle = const SystemUiOverlayStyle(
        statusBarColor: Color.fromARGB(0, 54, 45, 45),
        statusBarBrightness: Brightness.light,
        statusBarIconBrightness: Brightness.dark,
        systemNavigationBarDividerColor: Colors.transparent,
        systemNavigationBarColor: Colors.white,
        systemNavigationBarIconBrightness: Brightness.dark,
      );
      SystemChrome.setSystemUIOverlayStyle(systemUiOverlayStyle);
    }
  }

  /// 主题
  static ThemeData appTheme = ThemeData.light(useMaterial3: true).copyWith(
    colorScheme: ColorScheme.fromSeed(seedColor: kMainColor),
    primaryColor: kMainColor,
    appBarTheme: AppBarTheme(
      scrolledUnderElevation: 0.0,
      actionsPadding: EdgeInsets.symmetric(horizontal: 14.w),
      color: const Color(0xFFFFFFFF),
      centerTitle: true,
      titleTextStyle: TextStyle(
        fontSize: 17.sp,
        fontWeight: kMedium,
        color: kTitleColor,
      ),
    ),
    dividerTheme: const DividerThemeData(color: Color(0xFFF0F0F4), space: 0.5),
    scaffoldBackgroundColor: kPageBackgroundColor,
    scrollbarTheme: ScrollbarThemeData(
      thumbVisibility: WidgetStateProperty.all(false),
      thumbColor: WidgetStateProperty.all(Colors.white),
      radius: const Radius.circular(8),
    ),
  );
}
